/**
 @file ctc_phy_inc.h
 @copyright Copyright(C)  Centec Networks Inc.  All rights reserved.
 @date 2019-10-23
 @version v1.0
*/
#ifndef _CTC_PHY_INC_H
#define _CTC_PHY_INC_H

#include "sal.h"
#include "ctc_cli.h"
#include "ctc_api.h"
#include "ctcs_api.h"

enum phy_chip_mdio_type_e
{
    PHY_CHIP_MDIO_GE,
    PHY_CHIP_MDIO_XG
};

#if defined(ASW_ALONE)
#define CTC_CHIP_PHY_POLL_INTERVAL 10000
struct ctc_phy_port_s
{
    uint32 port_id;
    uint8 bus;
    uint8 phy_addr;
    uint32 phy_base_port;
    uint32 phy_last_port;
};
typedef struct ctc_phy_port_s ctc_phy_port_t;

static inline int32 cal_get_gchip_id(uint8 lchip, uint8* gchip)
{
    *gchip = 1;
    return 0;
}

static inline int32 cal_set_chip_prop(uint8 lchip, ctc_chip_property_t port_prop, void* p_value)
{
    return ctcs_chip_set_property(0, CTC_CHIP_PROP_REGISTER_PHY, p_value);
}

static inline int32 cal_phy_mdio_read(uint8 lchip, ctc_chip_mdio_type_t type, ctc_chip_mdio_para_t* p_para)
{
    return ctcs_chip_mdio_read(0, type, p_para);
}

static inline int32 cal_phy_mdio_write(uint8 lchip, ctc_chip_mdio_type_t type, ctc_chip_mdio_para_t* p_para)
{
    return ctcs_chip_mdio_write(0, type, p_para);
}

static inline int32 cal_cli_phy_mdio_read(uint8 lchip, uint16 type, uint16 dev_no, ctc_chip_mdio_para_t* p_para)
{
    if (type == PHY_CHIP_MDIO_GE)
    {
        type = CTC_CHIP_MDIO_GE;
        return cal_phy_mdio_read(lchip, type, p_para);
    }
    else
    {
        return CTC_E_FEATURE_NOT_SUPPORT;
    }
}

static inline int32 cal_cli_phy_mdio_write(uint8 lchip, uint16 type, uint16 dev_no, ctc_chip_mdio_para_t* p_para)
{
    if (type == PHY_CHIP_MDIO_GE)
    {
        type = CTC_CHIP_MDIO_GE;
        return cal_phy_mdio_write(lchip, type, p_para);
    }
    else
    {
        return CTC_E_FEATURE_NOT_SUPPORT;
    }
}

#else
#include "ctc_json.h"
#include "ctc_app_cfg_parse.h"

#define CTC_CHIP_PHY_POLL_INTERVAL 100

static inline int32 cal_get_gchip_id(uint8 lchip, uint8* gchip)
{
    if (g_ctcs_api_en)
    {
        return ctcs_get_gchip_id(lchip, gchip);
    }
    else
    {
        return ctc_get_gchip_id(lchip, gchip);
    }
}

static inline int32 cal_set_chip_prop(uint8 lchip, ctc_chip_property_t port_prop, void* p_value)
{
    if (g_ctcs_api_en)
    {
        return ctcs_chip_set_property(lchip, CTC_CHIP_PROP_REGISTER_PHY, p_value);
    }
    else
    {
        return ctc_chip_set_property(lchip, CTC_CHIP_PROP_REGISTER_PHY, p_value);
    }
}

static inline int32 cal_phy_mdio_read(uint8 lchip, ctc_chip_mdio_type_t type, ctc_chip_mdio_para_t* p_para)
{
    if (g_ctcs_api_en)
    {
        return ctcs_chip_mdio_read(lchip, type, p_para);
    }
    else
    {
        return ctc_chip_mdio_read(lchip, type, p_para);
    }
}

static inline int32 cal_phy_mdio_write(uint8 lchip, ctc_chip_mdio_type_t type, ctc_chip_mdio_para_t* p_para)
{
    if (g_ctcs_api_en)
    {
        return ctcs_chip_mdio_write(lchip, type, p_para);
    }
    else
    {
        return ctc_chip_mdio_write(lchip, type, p_para);
    }
}

static inline int32 cal_cli_phy_mdio_read(uint8 lchip, uint16 type, uint16 dev_no, ctc_chip_mdio_para_t* p_para)
{
    if (type == PHY_CHIP_MDIO_XG)
    {
        type = CTC_CHIP_MDIO_XG;
        p_para->dev_no = dev_no;
        return cal_phy_mdio_read(lchip, type, p_para);
    }
    else
    {
        type = CTC_CHIP_MDIO_GE;
        return cal_phy_mdio_read(lchip, type, p_para);
    }
}

static inline int32 cal_cli_phy_mdio_write(uint8 lchip, uint16 type, uint16 dev_no, ctc_chip_mdio_para_t* p_para)
{
    if (type == PHY_CHIP_MDIO_XG)
    {
        type = CTC_CHIP_MDIO_XG;
        p_para->dev_no = dev_no;
        return cal_phy_mdio_write(lchip, type, p_para);
    }
    else
    {
        type = CTC_CHIP_MDIO_GE;
        return cal_phy_mdio_write(lchip, type, p_para);
    }
}

#endif
#endif /*_CTC_PHY_INC_H */